package cn.lexi.vip.aspect.exception;

import cn.lexi.vip.exception.ExceptionLogger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Author Aaron
 */
@Aspect
@Component
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class DummyExceptionCatcher {

    @Autowired
    private ExceptionLogger exceptionLogger;

    private static final Logger LOGGER = LoggerFactory.getLogger(DummyExceptionCatcher.class);

    @Pointcut("@annotation(cn.lexi.vip.aspect.exception.DummyException)")
    private void dummyExceptionPointcut() {
    }

    @Around("dummyExceptionPointcut()")
    public Object catchEx(ProceedingJoinPoint pjp) {
        try {
            return pjp.proceed();
        } catch (Throwable e) {
            exceptionLogger.logException(LOGGER, e);
        }
        return null;
    }
}
